package org.stimuliband.dsp.goertzel;

import java.util.HashMap;
import java.util.Map;

public class CachedCoefficients extends Coefficients {

    final Map<Integer, Double> cache = new HashMap<>();

    public CachedCoefficients(int samplingRate, int probesGroupSize) {
        super(samplingRate, probesGroupSize);
    }

    @Override
    double coefficient(int forFrequence) {
        Double result = cache.get(forFrequence);
        if (result == null) {
            cache.put(forFrequence, super.coefficient(forFrequence));
            result = coefficient(forFrequence);
        }
        return result;
    }
}
